import axios from 'axios'

const service = axios.create({
    baseURL: process.env.VUE_APP_API,   // 基准地址 url = base url + request url
    timeout: 30000,
})

// 请求拦截器配置
service.interceptors.request.use(
    config => {
        let token = sessionStorage.getItem('token')
        if (token) {  // 携带token
            config.headers.Authorization = token
        }
        return config
    },
    error => {
        return Promise.reject(error.response)
    }
)

// 响应拦截器配置
service.interceptors.response.use(
    response => {
        return Promise.resolve(response.data)
    },
    error => {
        return Promise.reject(error.response)
    }
)


export default service





